package com.java.module.user.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.java.common.lang.domain.entity.User;
import com.java.common.service.ApiTokenService;
import com.java.common.utils.DateUtils;
import com.java.common.utils.ServletUtils;
import com.java.common.utils.bean.BeanUtils;
import com.java.module.user.domain.Feedback;
import com.java.module.user.domain.dto.FeedbackDTO;
import com.java.module.user.mapper.FeedbackMapper;
import com.java.module.user.service.IFeedbackService;

/**
 * 意见反馈Service业务层处理
 * 
 * @author Administrator
 * @date 2021-04-25
 */
@Service
public class FeedbackServiceImpl implements IFeedbackService {

    private final FeedbackMapper feedbackMapper;

    private final ApiTokenService tokenService;

    public FeedbackServiceImpl(FeedbackMapper feedbackMapper, ApiTokenService tokenService) {
        this.feedbackMapper = feedbackMapper;
        this.tokenService = tokenService;
    }

    /**
     * 查询意见反馈
     * 
     * @param id 意见反馈ID
     * @return 意见反馈
     */
    @Override
    public Feedback selectFeedbackById(Long id) {
        return feedbackMapper.selectFeedbackById(id);
    }

    /**
     * 查询意见反馈列表
     * 
     * @param feedback 意见反馈
     * @return 意见反馈
     */
    @Override
    public List<Feedback> selectFeedbackList(Feedback feedback) {
        return feedbackMapper.selectFeedbackList(feedback);
    }

    /**
     * 新增意见反馈
     * 
     * @param feedback 意见反馈
     * @return 结果
     */
    @Override
    public int insertFeedback(Feedback feedback) {
        feedback.setCreateTime(DateUtils.getNowDate());
        return feedbackMapper.insertFeedback(feedback);
    }

    /**
     * 修改意见反馈
     * 
     * @param feedback 意见反馈
     * @return 结果
     */
    @Override
    public int updateFeedback(Feedback feedback) {
        feedback.setUpdateTime(DateUtils.getNowDate());
        return feedbackMapper.updateFeedback(feedback);
    }

    /**
     * 批量删除意见反馈
     * 
     * @param ids 需要删除的意见反馈ID
     * @return 结果
     */
    @Override
    public int deleteFeedbackByIds(Long[] ids) {
        return feedbackMapper.deleteFeedbackByIds(ids);
    }

    /**
     * 删除意见反馈信息
     * 
     * @param id 意见反馈ID
     * @return 结果
     */
    @Override
    public int deleteFeedbackById(Long id) {
        return feedbackMapper.deleteFeedbackById(id);
    }

    @Override
    public int addFeedback(FeedbackDTO feedbackDTO) {
        User user = tokenService.getLoginUser().getUser();
        Feedback feedback = new Feedback();
        BeanUtils.copyBeanProp(feedback, feedbackDTO);
        feedback.setUid(user.getUid());
        feedback.setCreateBy(user.getUsername());
        feedback.setPlatform(ServletUtils.getPlatform());
        return insertFeedback(feedback);
    }

}